Crate common_path

source ·
Expand description

Calculates the common prefix for a set of paths, if a common prefix exists

Example

use std::path::{PathBuf, Path};
use common_path::common_path;

let baz = Path::new("/foo/bar/baz");
let quux = Path::new("/foo/bar/quux");
let prefix = common_path(baz, quux).unwrap();
assert_eq!(prefix, Path::new("/foo/bar").to_path_buf());

Or for more than 2 paths:

use std::path::{PathBuf, Path};
use common_path::common_path_all;

let baz = Path::new("/foo/bar/baz");
let quux = Path::new("/foo/bar/quux");
let foo = Path::new("/foo/bar/foo");
let prefix = common_path_all(vec![baz, quux, foo]).unwrap();
assert_eq!(prefix, Path::new("/foo/bar").to_path_buf());

Functions

Find the common prefix, if any, between 2 paths
Find the common prefix, if any, between any number of paths